#! /bin/sh --
# Small shell script to prepare the gnuplot sources when
# checked out from CVS.

# Note that autoconf 2.52 or newer is required; automake versions older than
# 1.7 might not work
# April 2012 - The AC_HEADER_STDBOOL macro is unreliable in autoconf versions < 2.68

# allow importing from the environment (mainly for FreeBSD; use
# "AUTOCONF=autoconf259 ... ./prepare")
ACLOCAL=${ACLOCAL:-aclocal}
AUTOCONF=${AUTOCONF:-autoconf}
AUTOHEADER=${AUTOHEADER:-autoheader}
AUTOMAKE=${AUTOMAKE:-automake}

chmod og-w docs/* >/dev/null 2>&1

# Clean up
rm -rf autom4te.cache config.cache config.status

if ${ACLOCAL} -I m4 && ${AUTOHEADER} \
  && (cd config && make -f Makefile.am.in Makefile.am ) \
  && (cd demo && make -f Makefile.am.in Makefile.am ) \
  && (cd m4 && make -f Makefile.am.in Makefile.am ) \
  && (cd term && make -f Makefile.am.in Makefile.am ) \
  && (cd tutorial && make -f Makefile.am.in Makefile.am ) \
  && ${AUTOMAKE} -a -c \
  && sed 's/noinst_PROGRAMS = bf_test$(EXEEXT) @GNUPLOT_X11@/noinst_PROGRAMS = bf_test$(EXEEXT) @GNUPLOT_X11@$(EXEEXT)/' \
	<src/Makefile.in >src/Makefile.in2 \
  && mv -f src/Makefile.in2 src/Makefile.in \
  && ${AUTOCONF}
then
  echo
  echo "The gnuplot source code was successfully prepared."
  echo "Run configure now, then make && make install to build and install gnuplot."
  echo
else
  echo
  echo "Some part of the preparation process failed."
  echo "Please refer to INSTALL for details."
  echo
  exit 1
fi

exit 0
